﻿using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace smartphone.App_Code
{
    public class Product
    {
        private int productID;
        private string productName;
        private string manufacturerName;
        private string productImage;
        private string productDesciption;
        private int productQuantity;
        private double productPrice;
        private DateTime productImportDate;
        private string productAccessory;
        private int productWarranty;
        private bool productHasRecord;
        private string productOS;
        private string productCPU;
        private float productCamera;
        private string productWifi;
        private string productAudio;
        private string productSensor;
        private string productMovie;
        private string promotion;
        private bool isDiscount;
        private bool publish;

        public bool Publish
        {
            get { return publish; }
            set { publish = value; }
        }

        public bool IsDiscount
        {
            get { return isDiscount; }
        }


        public string Promotion
        {
            get
            {
                return promotion;
            }
        }

        public string ProductAudio
        {
            get
            {
                return productAudio;
            }
        }

        public string ProductSensor
        {
            get
            {
                return productSensor;
            }
        }

        public string ProductMovie
        {
            get
            {
                return productMovie;
            }
        }


        public string ProductWifi
        {
            get
            {
                return productWifi;
            }
        }

        public float ProductCamera
        {
            get
            {
                return productCamera;
            }
        }

        public string ProductCPU
        {
            get
            {
                return productCPU;
            }
        }

        public string ProductOS
        {
            get
            {
                return productOS;
            }
        }

        public bool ProductHasRecord
        {
            get
            {
                return productHasRecord;
            }
        }

        public int ProductWarranty
        {
            get
            {
                return productWarranty;
            }
        }

        public string ProductAccessory
        {
            get
            {
                return productAccessory;
            }
        }

        public int ProductID
        {
            get
            {
                return productID;
            }
        }

        public string ProductName
        {
            get
            {
                return productName;
            }
        }

        public string ManufacturerName
        {
            get
            {
                return manufacturerName;
            }
        }

        public string ProductImage
        {
            get
            {
                return productImage;
            }
        }

        public string ProductDesciption
        {
            get
            {
                return productDesciption;
            }
        }

        public int ProductQuantity
        {
            get
            {
                return productQuantity;
            }
        }

        public double ProductPrice
        {
            get
            {
                return productPrice;
            }
        }


        public DateTime ProductImportDate
        {
            get
            {
                return productImportDate;
            }
        }

        /// <summary>
        /// Lay cac thuoc tinh cua san pham
        /// </summary>
        /// <param name="productID">Ma san pham</param>
        /// <returns></returns>
        public DataTable GetProductAttributes(int productID)
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "GetProductAttributes";

            DbParameter param = com.CreateParameter();
            param.ParameterName = "@productId";
            param.Value = productID;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            DataTable table = GenericDataAccess.ExecuteSelectCommand(com);
            return table;
        }

        /// <summary>
        /// Lây album hình ảnh sản phẩm
        /// </summary>
        /// <param name="productID">Ma san pham</param>
        /// <returns></returns>
        public DataTable GetProductAlbum(int productID)
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "GetProductAlbum";

            DbParameter param = com.CreateParameter();
            param.ParameterName = "@productId";
            param.Value = productID;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            DataTable table = GenericDataAccess.ExecuteSelectCommand(com);
            return table;
        }



        public DataTable GetProductDetail(int productID)
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "GetProductDetail";

            DbParameter param = com.CreateParameter();
            param.ParameterName = "@productID";
            param.Value = productID;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            DataTable table = GenericDataAccess.ExecuteSelectCommand(com);
            return table;
        }


        public Product GetProduct(int productID)
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "GetProductDetail";

            DbParameter param = com.CreateParameter();
            param.ParameterName = "@productID";
            param.Value = productID;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            DataTable table = GenericDataAccess.ExecuteSelectCommand(com);
            Product product = new Product();

            if (table.Rows.Count > 0)
            {
                DataRow row = table.Rows[0];
                //Date d = new Date(Int32.Parse(row["ngayNhap"].ToString()), Int32.Parse(row["ngayNhap"].ToString()), Int32.Parse(row["ngayNhap"].ToString()));

                product.productID = productID;
                product.productName = row["tenSanPham"].ToString();
                product.manufacturerName = row["tenHang"].ToString();
                product.productImage = row["HinhDaiDien"].ToString();
                product.productDesciption = row["moTa"].ToString();
                product.productQuantity = Int32.Parse(row["soLuong"].ToString());
                product.productPrice = Double.Parse(row["donGia"].ToString());
                //product.productImportDate = d;
                product.productAccessory = row["phuKien"].ToString();
                product.productWarranty = Int32.Parse(row["thoiGianBh"].ToString());
                product.productHasRecord = bool.Parse(row["ghiAm"].ToString());
                product.productOS = row["hdh"].ToString();
                product.productCPU = row["cpu"].ToString();
                product.productCamera = float.Parse(row["mayAnh"].ToString());
                product.productWifi = row["wifi"].ToString();
                product.productAudio = row["dinhDangNhac"].ToString();
                product.productSensor = row["camBien"].ToString();
                product.productMovie = row["dinhDangPhim"].ToString();
                product.promotion = row["noiDungKhuyenMai"].ToString();
                product.publish = bool.Parse(row["congBo"].ToString());
                if (row["giamGia"].ToString() != "")
                {
                    product.isDiscount = bool.Parse(row["giamGia"].ToString());
                }

            }

            return product;
        }


        /// <summary>
        /// Lay toan bo san pham trong cua hang
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <param name="howManyPages"></param>
        /// <returns></returns>
        public DataTable GetAllProducts(string pageNumber, out int howManyPages, string orderBy, string orderWay)
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "GetAllProducts";

            //mac dinh tieu chi sap xep la theo ten, tang dan tu a-> z
            if (orderBy == null)
                orderBy = "tenSanPham";
            if (orderWay == null)
                orderWay = "asc";

            //paremeter chua do dai tom tat
            DbParameter param = com.CreateParameter();
            param.ParameterName = "@doDaiTomTat";
            param.Value = ESmartConfig.ProductDescriptionLength;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //parameter chua so trang hien tai
            param = com.CreateParameter();
            param.ParameterName = "@soTrang";
            param.Value = pageNumber;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //parameter chua thong tin ve so san pham moi trang
            param = com.CreateParameter();
            param.ParameterName = "@sanPhamMoiTrang";
            param.Value = ESmartConfig.ProductsPerPage;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //chon tieu chi sap xep
            param = com.CreateParameter();
            param.ParameterName = "@sapxep";
            param.Value = orderBy;
            param.DbType = DbType.String;
            com.Parameters.Add(param);

            //chieu sap xep
            param = com.CreateParameter();
            param.ParameterName = "@cachsapxep";
            param.Value = orderWay;
            param.DbType = DbType.String;
            com.Parameters.Add(param);

            //param ve tong so luong san pham hien co
            param = com.CreateParameter();
            param.ParameterName = "@tongSanPham";
            param.Direction = ParameterDirection.Output;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);
            

            DataTable dataTable = GenericDataAccess.ExecuteSelectCommand(com);

            int howManyProducts = Int32.Parse(com.Parameters["@tongSanPham"].Value.ToString());
            howManyPages = (int)Math.Ceiling((double)howManyProducts / (double)ESmartConfig.ProductsPerPage);

            return dataTable;
        }


        /// <summary>
        /// Ham lay 12 san pham moi nhat trong cua hang
        /// </summary>
        /// <returns>Data table  san pham moi</returns>
        public DataTable GetNewProducts()
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "GetNewProducts";

            //paremeter chua do dai tom tat
            DbParameter param = com.CreateParameter();
            param.ParameterName = "@doDaiTomTat";
            param.Value = ESmartConfig.ProductDescriptionLength;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            DataTable dataTable = GenericDataAccess.ExecuteSelectCommand(com);

            return dataTable;
        }

        public DataTable GetProductsInSameManufacturer(int productID)
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "ProductsInSameManufacturer";

            //parameter chua ma san pham
            DbParameter param = com.CreateParameter();
            param.ParameterName = "@productId";
            param.Value = productID;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            DataTable table = GenericDataAccess.ExecuteSelectCommand(com);

            return table;
        }

        /// <summary>
        /// San pham theo hang san xuat
        /// </summary>
        /// <param name="manufacturerId">Ma hang san xuat</param>
        /// <param name="pageNumber">trang hien tai dang xem</param>
        /// <param name="howManyPages">tong so trang</param>
        /// <returns>Datatable cac san pham theo tung hang san xuat</returns>
        public DataTable GetProductsInManufacturer(string manufacturerId, string pageNumber, out int howManyPages, string orderBy, string orderWay)
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "ProductsInManufacturer";

            //mac dinh tieu chi sap xep la theo ten, tang dan tu a-> z
            if (orderBy == null)
                orderBy = "tenSanPham";
            if (orderWay == null)
                orderWay = "asc";

            //paremeter chua ma hang san xuat
            DbParameter param = com.CreateParameter();
            param.ParameterName = "@maHang";
            param.Value = manufacturerId;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //paremeter chua do dai tom tat
            param = com.CreateParameter();
            param.ParameterName = "@doDaiTomTat";
            param.Value = ESmartConfig.ProductDescriptionLength;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //parameter chua so trang hien tai
            param = com.CreateParameter();
            param.ParameterName = "@soTrang";
            param.Value = pageNumber;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //parameter chua thong tin ve so san pham moi trang
            param = com.CreateParameter();
            param.ParameterName = "@sanPhamMoiTrang";
            param.Value = ESmartConfig.ProductsPerPage;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //param ve tong so luong san pham hien co
            param = com.CreateParameter();
            param.ParameterName = "@tongSanPham";
            param.Direction = ParameterDirection.Output;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //chon tieu chi sap xep
            param = com.CreateParameter();
            param.ParameterName = "@sapxep";
            param.Value = orderBy;
            param.DbType = DbType.String;
            com.Parameters.Add(param);

            //chieu sap xep
            param = com.CreateParameter();
            param.ParameterName = "@cachsapxep";
            param.Value = orderWay;
            param.DbType = DbType.String;
            com.Parameters.Add(param);

            DataTable dataTable = GenericDataAccess.ExecuteSelectCommand(com);

            int howManyProducts = Int32.Parse(com.Parameters["@tongSanPham"].Value.ToString());
            howManyPages = (int)Math.Ceiling((double)howManyProducts / (double)ESmartConfig.ProductsPerPage);

            return dataTable;
        }


        /// <summary>
        /// Lay cac san pham dang duoc khuyen mai (trong thoi gian khuyen mai)
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <param name="howManyPages"></param>
        /// <param name="orderBy"></param>
        /// <param name="orderWay"></param>
        /// <returns></returns>
        public DataTable GetPromotionalProducts(string pageNumber, out int howManyPages, string orderBy, string orderWay)
        {
            DbCommand com = GenericDataAccess.CreateCommand();
            com.CommandText = "GetPromotionalProducts";

            //mac dinh tieu chi sap xep la theo ten, tang dan tu a-> z
            if (orderBy == null)
                orderBy = "tenSanPham";
            if (orderWay == null)
                orderWay = "asc";

            //paremeter chua do dai tom tat
            DbParameter param = com.CreateParameter();
            param.ParameterName = "@doDaiTomTat";
            param.Value = ESmartConfig.ProductDescriptionLength;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //parameter chua so trang hien tai
            param = com.CreateParameter();
            param.ParameterName = "@soTrang";
            param.Value = pageNumber;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //parameter chua thong tin ve so san pham moi trang
            param = com.CreateParameter();
            param.ParameterName = "@sanPhamMoiTrang";
            param.Value = ESmartConfig.ProductsPerPage;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);

            //chon tieu chi sap xep
            param = com.CreateParameter();
            param.ParameterName = "@sapxep";
            param.Value = orderBy;
            param.DbType = DbType.String;
            com.Parameters.Add(param);

            //chieu sap xep
            param = com.CreateParameter();
            param.ParameterName = "@cachsapxep";
            param.Value = orderWay;
            param.DbType = DbType.String;
            com.Parameters.Add(param);

            //param ve tong so luong san pham hien co
            param = com.CreateParameter();
            param.ParameterName = "@tongSanPham";
            param.Direction = ParameterDirection.Output;
            param.DbType = DbType.Int32;
            com.Parameters.Add(param);


            DataTable dataTable = GenericDataAccess.ExecuteSelectCommand(com);

            int howManyProducts = Int32.Parse(com.Parameters["@tongSanPham"].Value.ToString());
            howManyPages = (int)Math.Ceiling((double)howManyProducts / (double)ESmartConfig.ProductsPerPage);

            return dataTable;
        }

        /// <summary>
        /// Tim kiem san pham
        /// </summary>
        /// <param name="searchString">Tu khoan tim kiem</param>
        /// <param name="allWords">Tim kien ca cum tu hay rieng le tung tu</param>
        /// <param name="pageNumber">so trang de phan trang</param>
        /// <param name="howManyPages">tong so trang de hien thi san pham</param>
        /// <returns></returns>
        public DataTable Search(string searchString, string allWords,
            string pageNumber, out int howManyPages)
        {
            // get a configured DbCommand object
            DbCommand comm = GenericDataAccess.CreateCommand();
            // stored procedure ten
            comm.CommandText = "SearchCatalog";
            // Do dai tom tat
            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@DescriptionLength";
            param.Value = ESmartConfig.ProductDescriptionLength;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);
            // create a new parameter
            param = comm.CreateParameter();
            param.ParameterName = "@AllWords";
            param.Value = allWords.ToUpper() == "TRUE" ? "1" : "0";
            param.DbType = DbType.Byte;
            comm.Parameters.Add(param);
            // create a new parameter
            param = comm.CreateParameter();
            param.ParameterName = "@PageNumber";
            param.Value = pageNumber;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);
            // create a new parameter
            param = comm.CreateParameter();
            param.ParameterName = "@ProductsPerPage";
            param.Value = ESmartConfig.ProductsPerPage;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);
            // create a new parameter
            param = comm.CreateParameter();
            param.ParameterName = "@HowManyResults";
            param.Direction = ParameterDirection.Output;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            // so luong tu khoa tim lon nhat
            int howManyWords = 5;
            // chuyen tu khoa tim kiem thanh mot mang cac tu
            string[] words = Regex.Split(searchString, "[^a-zA-Z0-9]+");
            // add the words as stored procedure parameters
            int index = 1;
            for (int i = 0; i <= words.GetUpperBound(0) && index <= howManyWords; i++)
            // tu nao chi co 2 ki tu thi loai ra
            if (words[i].Length > 2)
            {
                // create the @Word parameters
                param = comm.CreateParameter();
                param.ParameterName = "@Word" + index.ToString();
                param.Value = words[i];
                param.DbType = DbType.String;
                comm.Parameters.Add(param);
                index++;
            }

            DataTable dbTable = GenericDataAccess.ExecuteSelectCommand(comm);
            int howManyProducts = Int32.Parse(comm.Parameters["@HowManyResults"].Value.ToString());
            howManyPages = (int)Math.Ceiling((double)howManyProducts / (double)ESmartConfig.ProductsPerPage);

            return dbTable;
        }


        /// <summary>
        /// Lay danh sach san pham cho giao dien admin
        /// </summary>
        /// <returns></returns>
        public DataTable GetProductForAdmin()
        {
            DbCommand comm = GenericDataAccess.CreateCommand();
            comm.CommandText = "GetProductForAdmin";

            DataTable table = GenericDataAccess.ExecuteSelectCommand(comm);
            return table;
        }


        /// <summary>
        /// Xoa san pham trong danh sach
        /// </summary>
        /// <param name="productID"></param>
        /// <returns></returns>
        public bool DeleteProduct(int productID)
        {
            DbCommand comm = GenericDataAccess.CreateCommand();
            comm.CommandText = "DeleteProduct";

            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@maSanPham";
            param.Value = productID;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            int result = -1;
            result = GenericDataAccess.ExecuteNonQuery(comm);
            return (result != -1);
        }


        /// <summary>
        /// Tao san pham moi
        /// </summary>
        /// <param name="tenSanPham"></param>
        /// <param name="maHang"></param>
        /// <param name="hinhDaiDien"></param>
        /// <param name="moTa"></param>
        /// <param name="soLuong"></param>
        /// <param name="donGia"></param>
        /// <param name="ngayNhap"></param>
        /// <param name="phuKien"></param>
        /// <param name="thoiGianBh"></param>
        /// <param name="ghiAm"></param>
        /// <param name="hdh"></param>
        /// <param name="cpu"></param>
        /// <param name="mayAnh"></param>
        /// <param name="wifi"></param>
        /// <param name="dinhDangNhac"></param>
        /// <param name="camBien"></param>
        /// <param name="dinhDangPhim"></param>
        /// <param name="mucGiamGia"></param>
        /// <returns></returns>
        public bool CreateProduct(string tenSanPham, int maHang, string hinhDaiDien, string moTa, int soLuong, double donGia, 
            DateTime ngayNhap, string phuKien, int thoiGianBh, bool ghiAm,
    		string hdh, string cpu, float mayAnh, string wifi, string dinhDangNhac,  string camBien, 
            string  dinhDangPhim, bool congBo)
        {
            DbCommand comm = GenericDataAccess.CreateCommand();
            comm.CommandText = "CreateProduct";

            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@tenSanPham";
            param.Value = tenSanPham;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@maHang";
            param.Value = maHang;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@hinhDaiDien";
            param.Value = hinhDaiDien;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@moTa";
            param.Value = moTa;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@soLuong";
            param.Value = soLuong;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@donGia";
            param.Value = donGia;
            param.DbType = DbType.Double;
            comm.Parameters.Add(param);


            param = comm.CreateParameter();
            param.ParameterName = "@ngayNhap";
            param.Value = ngayNhap;
            param.DbType = DbType.DateTime;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@phuKien";
            param.Value = phuKien;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@thoiGianBh";
            param.Value = thoiGianBh;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@ghiAm";
            param.Value = ghiAm;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@hdh";
            param.Value = hdh;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@cpu";
            param.Value = cpu;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@mayAnh";
            param.Value = mayAnh;
            param.DbType = DbType.Double;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@wifi";
            param.Value = wifi;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@dinhDangNhac";
            param.Value = dinhDangNhac;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@camBien";
            param.Value = camBien;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@dinhDangPhim";
            param.Value = dinhDangPhim;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@congBo";
            param.Value = congBo;
            param.DbType = DbType.Double;
            comm.Parameters.Add(param);

            int result = -1;
            result = GenericDataAccess.ExecuteNonQuery(comm);
            return (result != -1);
        }

        /// <summary>
        /// Cap nhat san pham trong cua hang
        /// </summary>
        /// <param name="maSanPham"></param>
        /// <param name="tenSanPham"></param>
        /// <param name="maHang"></param>
        /// <param name="hinhDaiDien"></param>
        /// <param name="moTa"></param>
        /// <param name="soLuong"></param>
        /// <param name="donGia"></param>
        /// <param name="ngayNhap"></param>
        /// <param name="phuKien"></param>
        /// <param name="thoiGianBh"></param>
        /// <param name="ghiAm"></param>
        /// <param name="hdh"></param>
        /// <param name="cpu"></param>
        /// <param name="mayAnh"></param>
        /// <param name="wifi"></param>
        /// <param name="dinhDangNhac"></param>
        /// <param name="camBien"></param>
        /// <param name="dinhDangPhim"></param>
        /// <param name="mucGiamGia"></param>
        /// <returns></returns>
        public bool UpdateProduct(int maSanPham, string tenSanPham, int maHang, string hinhDaiDien, string moTa, int soLuong, double donGia,
            DateTime ngayNhap, string phuKien, int thoiGianBh, bool ghiAm,
            string hdh, string cpu, float mayAnh, string wifi, string dinhDangNhac, string camBien,
            string dinhDangPhim, float mucGiamGia)
        {
            DbCommand comm = GenericDataAccess.CreateCommand();
            comm.CommandText = "CreateProduct";

            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@tenSanPham";
            param.Value = tenSanPham;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@maSanPham";
            param.Value = maSanPham;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@maHang";
            param.Value = maHang;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@hinhDaiDien";
            param.Value = hinhDaiDien;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@moTa";
            param.Value = moTa;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@soLuong";
            param.Value = soLuong;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@donGia";
            param.Value = donGia;
            param.DbType = DbType.Double;
            comm.Parameters.Add(param);


            param = comm.CreateParameter();
            param.ParameterName = "@ngayNhap";
            param.Value = ngayNhap;
            param.DbType = DbType.DateTime;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@phuKien";
            param.Value = phuKien;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@thoiGianBh";
            param.Value = thoiGianBh;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@ghiAm";
            param.Value = ghiAm;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@hdh";
            param.Value = hdh;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@cpu";
            param.Value = cpu;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@mayAnh";
            param.Value = mayAnh;
            param.DbType = DbType.Double;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@wifi";
            param.Value = wifi;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@dinhDangNhac";
            param.Value = dinhDangNhac;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@camBien";
            param.Value = camBien;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@dinhDangPhim";
            param.Value = dinhDangPhim;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@mucGiamGia";
            param.Value = mucGiamGia;
            param.DbType = DbType.Double;
            comm.Parameters.Add(param);

            int result = -1;
            result = GenericDataAccess.ExecuteNonQuery(comm);
            return (result != -1);
        }

        public bool CreateProductAlbum(string productID, string imageURL)
        {
            DbCommand comm = GenericDataAccess.CreateCommand();
            comm.CommandText = "CreateProductAlbum";

            DbParameter param = comm.CreateParameter();
            param.ParameterName = "@maSanPham";
            param.Value = productID;
            param.DbType = DbType.Int32;
            comm.Parameters.Add(param);

            param = comm.CreateParameter();
            param.ParameterName = "@imageUrl";
            param.Value = imageURL;
            param.DbType = DbType.String;
            comm.Parameters.Add(param);

            int result = -1;
            result = GenericDataAccess.ExecuteNonQuery(comm);
            return (result != -1);
        }
    }
}